def isPrime(x):
    if x == 1: return False
    y = True
    z = x - 1
    while z > 1:
        if not x % z:
            y = False
            break
        z -= 1
    return y

p = input()
c = []
for i in range(len(p)):
    for z in range(i + 1,len(p) + 1):
        x = int(p[i:z])
        if isPrime(x):
            c += [x]
print(max(c) if c else 0)
